Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid cloning jump threading state when possible #127024

Merged
merged 4 commits into from
Jun 30, 2024

Conversation

cjgillot
Copy link
Contributor

The current implementation of jump threading passes most of its time cloning its state. This PR attempts to avoid such clones by special-casing the last predecessor when recursing through a terminator.

This is not optimal, but a first step while I refactor the state data structure to be sparse.

The two other commits are drive-by.
Fixes #116721

r? @oli-obk

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 27, 2024
@rustbot
Copy link
Collaborator

rustbot commented Jun 27, 2024

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rust-log-analyzer

This comment has been minimized.

@cjgillot
Copy link
Contributor Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 27, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 27, 2024
Avoid cloning jump threading state when possible

The current implementation of jump threading passes most of its time cloning its state. This PR attempts to avoid such clones by special-casing the last predecessor when recursing through a terminator.

This is not optimal, but a first step while I refactor the state data structure to be sparse.

The two other commits are drive-by.
Fixes rust-lang#116721

r? `@oli-obk`
@bors
Copy link
Contributor

bors commented Jun 27, 2024

⌛ Trying commit 271b9c2 with merge e8f9a6f...

@rust-log-analyzer

This comment has been minimized.

Copy link
Contributor

@oli-obk oli-obk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me with ICE test removed (or moved to the UI test suite if you find it sufficiently useful)

@lqd
Copy link
Member

lqd commented Jun 27, 2024

The compile flags in the crash test are kinda sus, so here's another MCVE where only rustc -O is enough to ICE.

Minimized from the stable regression on lina in the original issue (playground):

pub struct NPlusOneArray<T>(T);

impl<T> AsRef<[T]> for NPlusOneArray<T>
where
    [T]: Copy,
{
    fn as_ref(&self) -> &[T] {
        todo!()
    }
}

@bors
Copy link
Contributor

bors commented Jun 27, 2024

☀️ Try build successful - checks-actions
Build commit: e8f9a6f (e8f9a6f672f6b26310aefebb6e44c630ed49b0af)

@rust-timer

This comment has been minimized.

@@ -846,9 +846,10 @@ impl Map {

if let ty::Ref(_, ref_ty, _) | ty::RawPtr(ref_ty, _) = ty.kind()
&& let ty::Slice(..) = ref_ty.kind()
// The user may have written a predicate like `[T]: Sized` in their where claures,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// The user may have written a predicate like `[T]: Sized` in their where claures,
// The user may have written a predicate like `[T]: Sized` in their where clauses,

self.find_opportunity(bb, state, cost, 0);
None
}

/// Recursion entry point to find threading opportunities.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

find_opportunity is not the entry-point anymore, right?

Suggested change
/// Recursion entry point to find threading opportunities.

bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 27, 2024
Make jump threading state sparse

Continuation of rust-lang#127024

Both dataflow const-prop and jump threading involve cloning the state vector a lot. This PR replaces the data structure by a sparse vector, considering:
- that jump threading state is typically very sparse (at most 1 or 2 set entries);
- that dataflow const-prop is disabled by default;
- that place/value map is very eager, and prone to creating an overly large state.

The first commit is shared with the previous PR to avoid needless conflicts.

r? `@oli-obk`
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (e8f9a6f): comparison URL.

Overall result: ❌ regressions - no action needed

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.2% [0.2%, 0.2%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 694.809s -> 696.87s (0.30%)
Artifact size: 326.69 MiB -> 326.77 MiB (0.03%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 27, 2024
@cjgillot cjgillot added the A-mir-opt Area: MIR optimizations label Jun 28, 2024
@cjgillot
Copy link
Contributor Author

The compile flags in the crash test are kinda sus, so here's another MCVE where only rustc -O is enough to ICE.

That's not very important, as this PR removed the assertion that used to trigger the ICE. For the future, what matters is remembering that [T]: Sized clauses can exist.

@cjgillot
Copy link
Contributor Author

@bors r=oli-obk

bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 30, 2024
Avoid cloning jump threading state when possible

The current implementation of jump threading passes most of its time cloning its state. This PR attempts to avoid such clones by special-casing the last predecessor when recursing through a terminator.

This is not optimal, but a first step while I refactor the state data structure to be sparse.

The two other commits are drive-by.
Fixes rust-lang#116721

r? `@oli-obk`
@bors
Copy link
Contributor

bors commented Jun 30, 2024

⌛ Testing commit c81481f with merge 29eb5a0...

@rust-log-analyzer
Copy link
Collaborator

The job x86_64-msvc-ext failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
[RUSTC-TIMING] miri test:false 63.376
[RUSTC-TIMING] miri test:false 3.047
    Finished `release` profile [optimized] target(s) in 0.39s
thread 'main' panicked at src/lib.rs:1697:17:
failed to copy `C:\a\rust\rust\build\x86_64-pc-windows-msvc\stage1-tools\x86_64-pc-windows-msvc\release\miri.exe` to `C:\a\rust\rust\build\x86_64-pc-windows-msvc\stage1-tools-bin\miri.exe`: The process cannot access the file because it is being used by another process. (os error 32)
##[endgroup]
Build completed unsuccessfully in 0:00:11
  local time: Sun, Jun 30, 2024  7:18:43 AM
  network time: Sun, 30 Jun 2024 07:18:43 GMT

@bors
Copy link
Contributor

bors commented Jun 30, 2024

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jun 30, 2024
@Kobzol
Copy link
Contributor

Kobzol commented Jun 30, 2024

Spurious error.

@bors retry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 30, 2024
@bors
Copy link
Contributor

bors commented Jun 30, 2024

⌛ Testing commit c81481f with merge 8e372cc...

bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 30, 2024
Avoid cloning jump threading state when possible

The current implementation of jump threading passes most of its time cloning its state. This PR attempts to avoid such clones by special-casing the last predecessor when recursing through a terminator.

This is not optimal, but a first step while I refactor the state data structure to be sparse.

The two other commits are drive-by.
Fixes rust-lang#116721

r? `@oli-obk`
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-msvc-ext failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
[RUSTC-TIMING] miri test:false 62.837
[RUSTC-TIMING] miri test:false 2.945
    Finished `release` profile [optimized] target(s) in 0.39s
thread 'main' panicked at src/lib.rs:1697:17:
failed to copy `C:\a\rust\rust\build\x86_64-pc-windows-msvc\stage1-tools\x86_64-pc-windows-msvc\release\miri.exe` to `C:\a\rust\rust\build\x86_64-pc-windows-msvc\stage1-tools-bin\miri.exe`: The process cannot access the file because it is being used by another process. (os error 32)
##[endgroup]
Build completed unsuccessfully in 0:00:08
  local time: Sun, Jun 30, 2024  9:40:47 AM
  network time: Sun, 30 Jun 2024 09:40:47 GMT

@bors
Copy link
Contributor

bors commented Jun 30, 2024

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jun 30, 2024
@cjgillot
Copy link
Contributor Author

@bors retry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 30, 2024
@bors
Copy link
Contributor

bors commented Jun 30, 2024

⌛ Testing commit c81481f with merge 2975a21...

@bors
Copy link
Contributor

bors commented Jun 30, 2024

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing 2975a21 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jun 30, 2024
@bors bors merged commit 2975a21 into rust-lang:master Jun 30, 2024
7 checks passed
@rustbot rustbot added this to the 1.81.0 milestone Jun 30, 2024
@cjgillot cjgillot deleted the jump-prof branch June 30, 2024 13:26
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (2975a21): comparison URL.

Overall result: ❌ regressions - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.6% [1.6%, 1.6%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary -4.4%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-4.4% [-4.4%, -4.4%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -4.4% [-4.4%, -4.4%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 695.533s -> 695.757s (0.03%)
Artifact size: 324.63 MiB -> 324.71 MiB (0.03%)

bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 1, 2024
Make jump threading state sparse

Continuation of rust-lang#127024

Both dataflow const-prop and jump threading involve cloning the state vector a lot. This PR replaces the data structure by a sparse vector, considering:
- that jump threading state is typically very sparse (at most 1 or 2 set entries);
- that dataflow const-prop is disabled by default;
- that place/value map is very eager, and prone to creating an overly large state.

The first commit is shared with the previous PR to avoid needless conflicts.

r? `@oli-obk`
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 2, 2024
Make jump threading state sparse

Continuation of rust-lang#127024

Both dataflow const-prop and jump threading involve cloning the state vector a lot. This PR replaces the data structure by a sparse vector, considering:
- that jump threading state is typically very sparse (at most 1 or 2 set entries);
- that dataflow const-prop is disabled by default;
- that place/value map is very eager, and prone to creating an overly large state.

The first commit is shared with the previous PR to avoid needless conflicts.

r? `@oli-obk`
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 3, 2024
Make jump threading state sparse

Continuation of rust-lang#127024

Both dataflow const-prop and jump threading involve cloning the state vector a lot. This PR replaces the data structure by a sparse vector, considering:
- that jump threading state is typically very sparse (at most 1 or 2 set entries);
- that dataflow const-prop is disabled by default;
- that place/value map is very eager, and prone to creating an overly large state.

The first commit is shared with the previous PR to avoid needless conflicts.

r? `@oli-obk`
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Jul 4, 2024
Make jump threading state sparse

Continuation of rust-lang/rust#127024

Both dataflow const-prop and jump threading involve cloning the state vector a lot. This PR replaces the data structure by a sparse vector, considering:
- that jump threading state is typically very sparse (at most 1 or 2 set entries);
- that dataflow const-prop is disabled by default;
- that place/value map is very eager, and prone to creating an overly large state.

The first commit is shared with the previous PR to avoid needless conflicts.

r? `@oli-obk`
lnicola pushed a commit to lnicola/rust-analyzer that referenced this pull request Jul 11, 2024
Make jump threading state sparse

Continuation of rust-lang/rust#127024

Both dataflow const-prop and jump threading involve cloning the state vector a lot. This PR replaces the data structure by a sparse vector, considering:
- that jump threading state is typically very sparse (at most 1 or 2 set entries);
- that dataflow const-prop is disabled by default;
- that place/value map is very eager, and prone to creating an overly large state.

The first commit is shared with the previous PR to avoid needless conflicts.

r? `@oli-obk`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-mir-opt Area: MIR optimizations merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ICE: slices are not scalars II
8 participants